package com.ruoyi.project.system.oederteamgoods.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.oederteamgoods.domain.OrderTeamGoods;
import com.ruoyi.project.system.oederteamgoods.service.IOrderTeamGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 拼团订单商品Controller
 * 
 * @author f_baisi
 * @date 2021-03-03
 */
@Controller
@RequestMapping("/system/oederteamgoods")
public class OrderTeamGoodsController extends BaseController
{
    private String prefix = "system/oederteamgoods";

    @Autowired
    private IOrderTeamGoodsService orderTeamGoodsService;

    @RequiresPermissions("system:oederteamgoods:view")
    @GetMapping()
    public String oederteamgoods()
    {
        return prefix + "/oederteamgoods";
    }

    /**
     * 查询拼团订单商品列表
     */
    @RequiresPermissions("system:oederteamgoods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderTeamGoods orderTeamGoods)
    {
        startPage();
        List<OrderTeamGoods> list = orderTeamGoodsService.selectOrderTeamGoodsList(orderTeamGoods);
        return getDataTable(list);
    }

    /**
     * 导出拼团订单商品列表
     */
    @RequiresPermissions("system:oederteamgoods:export")
    @Log(title = "拼团订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderTeamGoods orderTeamGoods)
    {
        List<OrderTeamGoods> list = orderTeamGoodsService.selectOrderTeamGoodsList(orderTeamGoods);
        ExcelUtil<OrderTeamGoods> util = new ExcelUtil<OrderTeamGoods>(OrderTeamGoods.class);
        return util.exportExcel(list, "oederteamgoods");
    }

    /**
     * 新增拼团订单商品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存拼团订单商品
     */
    @RequiresPermissions("system:oederteamgoods:add")
    @Log(title = "拼团订单商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderTeamGoods orderTeamGoods)
    {
        return toAjax(orderTeamGoodsService.insertOrderTeamGoods(orderTeamGoods));
    }

    /**
     * 修改拼团订单商品
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OrderTeamGoods orderTeamGoods = orderTeamGoodsService.selectOrderTeamGoodsById(id);
        mmap.put("orderTeamGoods", orderTeamGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存拼团订单商品
     */
    @RequiresPermissions("system:oederteamgoods:edit")
    @Log(title = "拼团订单商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderTeamGoods orderTeamGoods)
    {
        return toAjax(orderTeamGoodsService.updateOrderTeamGoods(orderTeamGoods));
    }

    /**
     * 删除拼团订单商品
     */
    @RequiresPermissions("system:oederteamgoods:remove")
    @Log(title = "拼团订单商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderTeamGoodsService.deleteOrderTeamGoodsByIds(ids));
    }
}
